package com.zx.BookSeaReader.greendao.gen;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.zx.BookSeaReader.greendao.entity.BookCommentBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "BOOK_COMMENT_BEAN".
*/
public class BookCommentBeanDao extends AbstractDao<BookCommentBean, Long> {

    public static final String TABLENAME = "BOOK_COMMENT_BEAN";

    /**
     * Properties of entity BookCommentBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property CommentId = new Property(0, Long.class, "commentId", true, "_id");
        public final static Property Username = new Property(1, String.class, "username", false, "USERNAME");
        public final static Property Content = new Property(2, String.class, "content", false, "CONTENT");
        public final static Property Type = new Property(3, String.class, "type", false, "TYPE");
        public final static Property LikeCount = new Property(4, int.class, "likeCount", false, "LIKE_COUNT");
        public final static Property FloorCount = new Property(5, int.class, "floorCount", false, "FLOOR_COUNT");
        public final static Property HaveImage = new Property(6, boolean.class, "haveImage", false, "HAVE_IMAGE");
        public final static Property CreateTime = new Property(7, String.class, "createTime", false, "CREATE_TIME");
        public final static Property BookId = new Property(8, String.class, "bookId", false, "BOOK_ID");
        public final static Property ListId = new Property(9, Long.class, "listId", false, "LIST_ID");
    }

    private Query<BookCommentBean> bookListBean_CommentBeansQuery;

    public BookCommentBeanDao(DaoConfig config) {
        super(config);
    }
    
    public BookCommentBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"BOOK_COMMENT_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: commentId
                "\"USERNAME\" TEXT," + // 1: username
                "\"CONTENT\" TEXT," + // 2: content
                "\"TYPE\" TEXT," + // 3: type
                "\"LIKE_COUNT\" INTEGER NOT NULL ," + // 4: likeCount
                "\"FLOOR_COUNT\" INTEGER NOT NULL ," + // 5: floorCount
                "\"HAVE_IMAGE\" INTEGER NOT NULL ," + // 6: haveImage
                "\"CREATE_TIME\" TEXT," + // 7: createTime
                "\"BOOK_ID\" TEXT," + // 8: bookId
                "\"LIST_ID\" INTEGER);"); // 9: listId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK_COMMENT_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, BookCommentBean entity) {
        stmt.clearBindings();
 
        Long commentId = entity.getCommentId();
        if (commentId != null) {
            stmt.bindLong(1, commentId);
        }
 
        String username = entity.getUsername();
        if (username != null) {
            stmt.bindString(2, username);
        }
 
        String content = entity.getContent();
        if (content != null) {
            stmt.bindString(3, content);
        }
 
        String type = entity.getType();
        if (type != null) {
            stmt.bindString(4, type);
        }
        stmt.bindLong(5, entity.getLikeCount());
        stmt.bindLong(6, entity.getFloorCount());
        stmt.bindLong(7, entity.getHaveImage() ? 1L: 0L);
 
        String createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindString(8, createTime);
        }
 
        String bookId = entity.getBookId();
        if (bookId != null) {
            stmt.bindString(9, bookId);
        }
 
        Long listId = entity.getListId();
        if (listId != null) {
            stmt.bindLong(10, listId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, BookCommentBean entity) {
        stmt.clearBindings();
 
        Long commentId = entity.getCommentId();
        if (commentId != null) {
            stmt.bindLong(1, commentId);
        }
 
        String username = entity.getUsername();
        if (username != null) {
            stmt.bindString(2, username);
        }
 
        String content = entity.getContent();
        if (content != null) {
            stmt.bindString(3, content);
        }
 
        String type = entity.getType();
        if (type != null) {
            stmt.bindString(4, type);
        }
        stmt.bindLong(5, entity.getLikeCount());
        stmt.bindLong(6, entity.getFloorCount());
        stmt.bindLong(7, entity.getHaveImage() ? 1L: 0L);
 
        String createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindString(8, createTime);
        }
 
        String bookId = entity.getBookId();
        if (bookId != null) {
            stmt.bindString(9, bookId);
        }
 
        Long listId = entity.getListId();
        if (listId != null) {
            stmt.bindLong(10, listId);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public BookCommentBean readEntity(Cursor cursor, int offset) {
        BookCommentBean entity = new BookCommentBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // commentId
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // username
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // content
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // type
            cursor.getInt(offset + 4), // likeCount
            cursor.getInt(offset + 5), // floorCount
            cursor.getShort(offset + 6) != 0, // haveImage
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // createTime
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // bookId
            cursor.isNull(offset + 9) ? null : cursor.getLong(offset + 9) // listId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, BookCommentBean entity, int offset) {
        entity.setCommentId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setUsername(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setContent(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setType(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setLikeCount(cursor.getInt(offset + 4));
        entity.setFloorCount(cursor.getInt(offset + 5));
        entity.setHaveImage(cursor.getShort(offset + 6) != 0);
        entity.setCreateTime(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setBookId(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
        entity.setListId(cursor.isNull(offset + 9) ? null : cursor.getLong(offset + 9));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(BookCommentBean entity, long rowId) {
        entity.setCommentId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(BookCommentBean entity) {
        if(entity != null) {
            return entity.getCommentId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(BookCommentBean entity) {
        return entity.getCommentId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "commentBeans" to-many relationship of BookListBean. */
    public List<BookCommentBean> _queryBookListBean_CommentBeans(Long listId) {
        synchronized (this) {
            if (bookListBean_CommentBeansQuery == null) {
                QueryBuilder<BookCommentBean> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.ListId.eq(null));
                bookListBean_CommentBeansQuery = queryBuilder.build();
            }
        }
        Query<BookCommentBean> query = bookListBean_CommentBeansQuery.forCurrentThread();
        query.setParameter(0, listId);
        return query.list();
    }

}
